package com.ruoyi.crm.controller;

import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.crm.domain.CrmVisitObjectives;
import com.ruoyi.crm.service.ICrmVisitObjectivesService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 拜访目标Controller
 * 
 * @author ruoyi
 * @date 2022-01-29
 */
@RestController
@RequestMapping("/objectives")
public class CrmVisitObjectivesController extends BaseController
{
    @Autowired
    private ICrmVisitObjectivesService crmVisitObjectivesService;

    /**
     * 查询拜访目标列表
     */
    @RequiresPermissions("crm:objectives:list")
    @GetMapping("/list")
    public TableDataInfo list(CrmVisitObjectives crmVisitObjectives)
    {
        startPage();
        List<CrmVisitObjectives> list = crmVisitObjectivesService.selectCrmVisitObjectivesList(crmVisitObjectives);
        return getDataTable(list);
    }

    /**
     * 导出拜访目标列表
     */
    @RequiresPermissions("crm:objectives:export")
    @Log(title = "拜访目标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmVisitObjectives crmVisitObjectives)
    {
        List<CrmVisitObjectives> list = crmVisitObjectivesService.selectCrmVisitObjectivesList(crmVisitObjectives);
        ExcelUtil<CrmVisitObjectives> util = new ExcelUtil<CrmVisitObjectives>(CrmVisitObjectives.class);
        util.exportExcel(response, list, "拜访目标数据");
    }

    /**
     * 获取拜访目标详细信息
     */
    @RequiresPermissions("crm:objectives:query")
    @GetMapping(value = "/{visitObjectivesId}")
    public AjaxResult getInfo(@PathVariable("visitObjectivesId") Long visitObjectivesId)
    {
        return AjaxResult.success(crmVisitObjectivesService.selectCrmVisitObjectivesByVisitObjectivesId(visitObjectivesId));
    }

    /**
     * 新增拜访目标
     */
    @RequiresPermissions("crm:objectives:add")
    @Log(title = "拜访目标", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmVisitObjectives crmVisitObjectives)
    {
        crmVisitObjectives.setVisitObjectivesUserId(SecurityUtils.getUserId());
        crmVisitObjectives.setVisitObjectivesUserName(SecurityUtils.getUsername());
        crmVisitObjectives.setVisitObjectivesDate(new Date());
        return toAjax(crmVisitObjectivesService.insertCrmVisitObjectives(crmVisitObjectives));
    }

    /**
     * 修改拜访目标
     */
    @RequiresPermissions("crm:objectives:edit")
    @Log(title = "拜访目标", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmVisitObjectives crmVisitObjectives)
    {
        return toAjax(crmVisitObjectivesService.updateCrmVisitObjectives(crmVisitObjectives));
    }

    /**
     * 删除拜访目标
     */
    @RequiresPermissions("crm:objectives:remove")
    @Log(title = "拜访目标", businessType = BusinessType.DELETE)
	@DeleteMapping("/{visitObjectivesIds}")
    public AjaxResult remove(@PathVariable Long[] visitObjectivesIds)
    {
        return toAjax(crmVisitObjectivesService.deleteCrmVisitObjectivesByVisitObjectivesIds(visitObjectivesIds));
    }
}
